import { axiosInstance } from 'src/boot/axios'
import CommonConfig from 'src/assets/js/config'

const baseUrlProcessPlan = CommonConfig.planningUrl + '/v1'

// 列举工序计划列表
export function getProcessPlanList (endAfter, endBefore, keyword, pageNum, pageSize, searchBy, startAfter, startBefore, statusCode) {
  const newUrl = `${baseUrlProcessPlan}/process_plannings`

  let reqData = {
    params: {
      endAfter: endAfter || undefined,
      endBefore: endBefore || undefined,
      keyword: keyword || undefined,
      pageNum,
      pageSize,
      searchBy: searchBy || undefined,
      startAfter: startAfter || undefined,
      startBefore: startBefore || undefined,
      statusCode
    }
  }
  return axiosInstance.get(newUrl, reqData).then((res) => {
    return Promise.resolve(res)
  })
}

// 编辑计划
export function editPlan (query) {
  const newUrl = `${baseUrlProcessPlan}/process_plannings/${query.id}`

  return axiosInstance.put(newUrl, query).then(resp => {
    return Promise.resolve(resp)
  })
}

// 删除工序计划
export function deleteProcessPlan (id) {
  const newUrl = `${baseUrlProcessPlan}/process_plannings/${id}`

  return axiosInstance.delete(newUrl).then((res) => {
    return Promise.resolve(res)
  })
}

// 强制关闭工序计划
export function closeProcessPlan (id) {
  const newUrl = `${baseUrlProcessPlan}/process_plannings/forced_close/${id}`

  return axiosInstance.patch(newUrl).then((res) => {
    return Promise.resolve(res)
  })
}
